How can I fix my Python code to correctly validate IP addresses

welcome to shbcf.ru